<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户修改</title>

    <script src="../js/vue.global.js"></script>
    <script src="../js/vue-router.global.js"></script>
    <script src="../js/axios.min.js"></script>

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }

        #app {
            max-width: 600px;
            margin: 30px auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            padding: 30px;
        }

        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
            font-weight: 600;
        }

        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            display: block;
            width: 100%;
            margin: 20px 0;
            font-weight: 500;
        }

        button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        button:active {
            transform: translateY(0);
        }

        .form-container {
            margin-top: 30px;
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: border 0.3s ease;
        }

        input:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        .submit-btn {
            background-color: #2ecc71;
        }

        .submit-btn:hover {
            background-color: #27ae60;
        }

        .edit-btn {
            background-color: #3498db;
        }

        .message {
            padding: 15px;
            border-radius: 6px;
            margin-bottom: 20px;
            text-align: center;
            font-weight: 500;
        }

        .success {
            background-color: #d4edda;
            color: #155724;
        }

        .error {
            background-color: #f8d7da;
            color: #721c24;
        }
    </style>
</head>

<body>

<div id="app">
    <h1>修改用户信息</h1>
    <button @click="editUser">编辑个人信息</button>
    <div v-if="visibleUser">
        <label for="username">用户名:</label>
        <input type="text" id="username" v-model="user.username"><br/>
        <label for="email">邮箱:</label>
        <input type="text" id="email" v-model="user.email"><br/>
        <label for="phone">手机号:</label>
        <input type="text" id="phone" v-model="user.phone"><br/>
        <button @click="updateUser">提交修改</button>
    </div>

<script>
    const app=Vue.createApp({
        data(){
            return{
                user: {},
                visibleUser: false
            }
        },
        methods:{
            updateUser() {
                axios.put('/user', this.user)
                    .then(response => {
                        console.log(response.data);
                        alert('修改成功');
                    })
                    .catch(error => {
                        console.log(error);
                        alert('修改失败');
                    });
                this.visibleUser = false;
                this.user = {};
                location.href = "./mine.html";
            },
            editUser() {
                console.log("editUser")

                console.log(this.user)
                axios.get('/user').then(response => {
                    this.user = response.data;
                    this.visibleUser = true;
                    console.log(response.data);
                }).catch(error => {
                    console.log(error);
                    alert('获取用户信息失败');
                });

            }
        }
    });
    app.mount('#app')

</script>

</body>
</html>